/// Copyright (c) zhuzichu520
/// https://github.com/zhuzichu520/FluentUI
/// This file is licensed under MIT
#include "Components/FpsItem.h"

#include <QQuickWindow>
#include <QTimer>

FpsItem::FpsItem() {
  QTimer* timer = new QTimer(this);
  connect(timer, &QTimer::timeout, this, [this] {
    fps(_frameCount);
    _frameCount = 0;
  });
  connect(this, &QQuickItem::windowChanged, this, [this] {
    if (window()) {
      connect(
          window(), &QQuickWindow::afterRendering, this,
          [this] { _frameCount++; }, Qt::DirectConnection);
    }
  });
  timer->start(1000);
}
